<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .outer {
      position: relative;
      margin: 100px;
      background-color: brown;
      width: 200px;
      height: 200px;
    }

    .inner {
      background-color: cadetblue;
      width: 100px;
      height: 100px;
      position: absolute;
      left: 100px;
      top: 100px;
    }
  </style>
</head>

<body>
  <div class="outer">
    <div class="inner"></div>
  </div>

  <script src="./jquery-3.6.0.js"></script>
  <script>

    console.log($('.inner').offset()); // 相对页面的位置 {top: 200, left: 200}

    console.log($('.inner').position()); // 相对于父元素的位置 {top: 100, left: 100}


    // 如果给 offset 传递参数，表示设置元素的位置
    $('.inner').offset({ top: 50, left: 50 })

  </script>
</body>

</html>